var a = getApp().globalData.api, e = getApp();

Page({
    data: {
        payData: null,
        isCheck: !1
    },
    onLoad: function(e) {
        var t = this;
        e.hasOwnProperty("orderId") ? a.getPort("getPayInfo", {
            rest: e.orderId
        }).then(function(a) {
            1 == a.values.offlineAmt ? wx.navigateTo({
                url: "/pages/order/pay_succeed/pay_succeed?orderId=" + e.orderId
            }) : t.setData({
                payData: a.values
            });
        }, function(a) {
            wx.switchTab({
                url: "/pages/homepages/homepages"
            });
        }) : wx.switchTab({
            url: "/pages/homepages/homepages"
        });
    },
    choice: function(a) {
        this.setData({
            isCheck: !this.data.isCheck
        });
    },
    pay: a.throttle(function(a, t) {
        a.data.isCheck ? wx.checkSession({
            success: function() {
                console.log(11), a.readPay();
            },
            fail: function() {
                e.getOpenId().then(function(e) {
                    a.readPay();
                }, function(a) {});
            }
        }) : wx.showToast({
            title: "请选择支付方式",
            icon: "none",
            mask: !0
        });
    }, 1e3),
    readPay: function() {
        var t = this, n = '{"openId":"'.concat(wx.getStorageSync("openId"), '"}'), o = {
            orderId: this.data.payData.id,
            payChannel: e.globalData.appInfo.payChannel,
            mchId: e.globalData.appInfo.mchId,
            extra: n
        };
        a.postPort("payOrder", o, !0).then(function(a) {
            var e = JSON.parse(a.values);
            console.log(e);
            var n = t;
            wx.requestPayment({
                timeStamp: e.payParams.timeStamp,
                nonceStr: e.payParams.nonceStr,
                package: e.payParams.package,
                signType: e.payParams.signType,
                paySign: e.payParams.paySign,
                success: function(a) {
                    "requestPayment:ok" == a.errMsg && wx.navigateTo({
                        url: "/pages/order/pay_succeed/pay_succeed?orderId=" + n.data.payData.id
                    });
                },
                fail: function(a) {},
                complete: function(a) {}
            });
        }, function(a) {
            console.log(a);
        });
    },
    onShow: function() {}
});